<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Title</title>
  </head>
  <body>
  
  </body>
  
  <script>
    /*创建与调用*/
    {
      /*1.函数对象创建*/
      var fun1 = new Function("console.log('Function创建方式')")
      fun1();
      
      /*2.函数声明创建*/
      function fun2() {
        console.log('函数声明创建');
      }
      
      console.log(fun2());//undefined
      /*3.匿名函数创建*/
      var fun3 = function () {
        console.log('匿名函数创建');
      }
      console.log(fun3());//undefined
    }
    
    
    /*输出函数*/
    {
      /*1.页面输出*/
      document.write('页面输出')
      /*2.控制台输出*/
      console.log("输出一条日志");//最常用
      console.info("输出一条信息");
      console.warn("输出一条警告");
      console.error("输出一条错误");
      /*3.弹窗输出*/
      alert('alter弹窗');
      prompt('prompt弹窗', '默认值');
      confirm('confirm弹窗');
    }
    
    
    /*时间函数*/
    {
      /*`setInterval("XXX",time)`表示**每隔**`time`毫秒调用一次`XXX`*/
      /*setInterval(function () {
          document.write('setInterval\n');
      },100);*/
      setTimeout(function () {
        document.write('setTimeout\n');
      }, 100);
    }
    
    /*call*/
    {
      var obj = {
        num: 10
      }
      
      function func(a, b) {
        return this.num + a + b
      }
      
      console.log(func(1, 2));//NaN
      console.log(func.call(obj, 1, 2));//13
    }
    
    /*apply*/
    {
      var obj = {
        num: 10
      }
      
      function func(a, b) {
        return this.num + a + b
      }
      
      console.log(func(1, 2));//NaN
      console.log(func.apply(obj, [1, 2]));//13
    }
    
    /*bind*/
    {
      var obj = {
        num: 10
      }
      
      function func(a, b) {
        return this.num + a + b
      }
      
      console.log(func(1, 2));//NaN
      console.log(func.bind(obj));//func(a, b) { return this.num + a + b }
      console.log(func.bind(obj)(1, 2));//13
      console.log(func.bind(obj, 1, 2)());//13
      console.log(func.bind(obj, 1, 2)(3, 4));//13
      console.log(func.bind(obj, 1)(4));//15
      console.log(func.bind(obj, 1)(4, 5));//15
    }
    
    /*eval*/
    {
      let arr = eval("['aa','bb','cc']");
      console.log(arr[0]);//aa
      
      eval("console.log('激活')")//激活
    }
  </script>
</html>